package dai.learn.write.wrapper;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 *
 * @author daify
 * @create 2019-03-22 14:22
 **/
public class XSSFWorkbookWrapper {
    
    private XSSFWorkbook workbook;
    private XSSFSheet    sheetAt;
    
    public XSSFWorkbookWrapper () {
        workbook = new XSSFWorkbook();
        sheetAt = workbook.createSheet("main");
    }
    
    public void initTitile(List<String> titles) {
        XSSFRow row = sheetAt.createRow(0);
        AtomicInteger index = new AtomicInteger(0);
        titles.forEach(title -> {
            XSSFCell cell =
                    row.getCell(index.get()) == null ? row.createCell(index.get()) : row.getCell(index.get());
            cell.setCellValue(title);
            index.addAndGet(0);
        });
    }

    public XSSFWorkbook getWorkbook() {
        return workbook;
    }
}
